package com.cheng.io.demo;

import java.io.*;

/**
 * 简单文件拷贝，使用缓冲字节输入(BufferedInputStream)输出(BufferedOutputStream)流实现
 */
public class FileCopyByBufferedInputOutputStreamImpl {
    public static void main(String[] args) {
        long begin = System.currentTimeMillis();

        String oldPath = "io/resources/特性.txt";
        String newPath = "io/resources/特性1.txt";
        try (
                BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(oldPath));
                BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(newPath));
        ) {
            byte[] bytes = new byte[1024];
            int readCount;
            while ((readCount = bufferedInputStream.read(bytes)) != -1) {
                bufferedOutputStream.write(bytes, 0, readCount);
            }

            bufferedOutputStream.flush();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        long end = System.currentTimeMillis();
        System.out.println("TotalTime:" + (end - begin) + "ms");
    }
}
